
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="./kamichaxun.css" rel="stylesheet">
   <title>火火淘电子商城卡密查询</title>
 
    
	
</head>
<body>
<!-- 导航栏 -->
<header class="navbar">
    <div class="container nav-container">
        <a href="http://hht.wa541.cn" class="logo">火火淘商城卡密查询系统</a>
        <ul class="nav-links">

           <li><a href="#" class="active">余额查询</a></li>
        
        </ul>
    </div>
</header>

<!-- 余额查询区域 -->
<div class="container">
    <div class="balance-query">
        <div class="query-header">
            <h2>火火淘充值卡余额查询</h2>
            <p>请输入您的卡片信息查询余额</p>
        </div>

        <form class="query-form" id="balanceForm">
            <div class="form-group">
                <label for="cardNumber">卡号</label>
                <input type="text" id="cardNumber" class="form-control" placeholder="请输入卡号" required>
            </div>

            <div class="form-group">
                <label for="cardPassword">卡密</label>
                <input type="password" id="cardPassword" class="form-control" placeholder="请输入卡密" required>
            </div>

            <div class="form-group">
                <label for="captcha">验证码</label>
                <div class="captcha-container">
                    <input type="text" id="captcha" name="captcha" class="form-control" placeholder="请输入验证码" required>
                    <!-- 前端生成的验证码显示区域 -->
                    <div id="captchaImage" class="captcha-img" title="点击刷新验证码"></div>
                </div>
            </div>

            <button type="submit" class="btn-submit">查询余额</button>
        </form>

        <div class="query-result" id="queryResult" style="display: none">
            <h3 class="result-heading">查询结果</h3>
            <div class="result-details">
                <div class="result-item">
                    <span class="result-label">卡号</span>
                    <span class="result-value" id="resultCardNumber">-</span>
                </div>
                <div class="result-item">
                    <span class="result-label">卡片状态</span>
                    <span class="result-value" id="resultCardStatus">-</span>
                </div>
                <div class="result-item">
                    <span class="result-label">卡名称</span>
                    <span class="result-value" id="resultCardName">-</span>
                </div>
                <div class="result-item">
                    <span class="result-label">卡面值</span>
                    <span class="result-value" id="resultCardValue">-</span>
                </div>
                <div class="result-item" id="resultExpiryItem">
                    <span class="result-label">有效期至</span>
                    <span class="result-value" id="resultExpiry">-</span>
                </div>
                <div class="result-item" id="resultUsageDateItem">
                    <span class="result-label">使用日期</span>
                    <span class="result-value" id="resultUsageDate">-</span>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 页脚 -->
<footer class="footer">
    <div class="container">
        <div class="footer-grid">
            <div class="footer-column">
                <h3>关于我们</h3>
                <p>火火淘电子商城优质的精品资源每日都会更新</p>
				 <p>资源大部分都是通过积分获取，签到可以获取免费的积分</p>
				  <p>暂时只支持卡密充值，暂未开放其他充值途径左</p>
				  
            </div>

            <div class="footer-column">
                <h3>快速链接</h3>
                  <ul>


                    <li><a href="http://hht.wa541.cn">官方主页</a></li>
					<li><a href="http://hht.wa541.cn/szyc">原创实践</a></li>
					<li><a href="http://hht.wa541.cn/ztmh">主题美化</a></li>
					<li><a href="http://hht.wa541.cn/yxdzhj">游戏大作</a></li>
					<li><a href="http://hht.wa541.cn/jxym">精选源码</a></li>
			   	    <li><a href="http://hht.wa541.cn/yue">余额查询</a></li>
                </ul>
            </div>

            <div class="footer-column">
                <h3>联系我们</h3>
                <ul>
                      <li><i class="fas fa-envelope"></i> Q:4504132</li>
                    <li><i class="fas fa-envelope"></i> V:4504132</li>
                    <li><i class="fas fa-envelope"></i> hhtpay@gmail.com</li>
                </ul>
            </div>
        </div>

        <div class="copyright">
          <p>Copyright © 2025 · 备案号：渝ICP备2025059831号-24 </p>
        </div>
    </div>
</footer>

<script>
    // 存储当前验证码值
    let currentCaptcha = '';

    // 生成随机验证码
    function generateCaptcha() {
        const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        let captcha = '';
        for (let i = 0; i < 4; i++) {
            captcha += chars.charAt(Math.floor(Math.random() * chars.length));
        }
        return captcha;
    }

    // 更新验证码显示
    function refreshCaptcha() {
        currentCaptcha = generateCaptcha();
        const captchaImage = document.getElementById('captchaImage');
        captchaImage.textContent = currentCaptcha;
    }

    // 初始化验证码
    refreshCaptcha();

    // 点击验证码刷新
    document.getElementById('captchaImage').addEventListener('click', function() {
        refreshCaptcha();
    });

    // 表单提交处理 - 替换原有逻辑
    document.getElementById('balanceForm').addEventListener('submit', async function(e) {
        e.preventDefault();

        // 获取表单值
        const cardNumber = document.getElementById('cardNumber').value;
        const cardPassword = document.getElementById('cardPassword').value;
        const captcha = document.getElementById('captcha').value.toUpperCase(); // 转换为大写进行比较

        // 前端验证码校验
        if (captcha !== currentCaptcha) {
            alert('验证码错误，请重新输入');
            refreshCaptcha();
            document.getElementById('captcha').value = '';
            return;
        }

        try {
            // 调用后端接口（验证码已在前端验证，不需要发送到后端）
            const response = await fetch('http://101.pay123.shop/api/v1/card/check', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
                },
                body: new URLSearchParams({
                    card_number: cardNumber,
                    card_key: cardPassword
                })
            });

            const result = await response.json();

            // 处理响应
            if (result.code === 200) { // 成功码
                updateResultUI(result.data);
            } else {
                showError2(result.msg || '查询失败');
            }
        } catch (error) {
            showError2('网络请求异常，请重试');
        } finally {
            // 刷新验证码
            refreshCaptcha();
            document.getElementById('captcha').value = '';
        }
    });

    // 更新UI显示结果
    function updateResultUI(data) {
        // 重置显示状态
        document.getElementById('resultExpiryItem').classList.remove('hidden-item');
        document.getElementById('resultUsageDateItem').classList.remove('hidden-item');

        // 填充数据
        document.getElementById('resultCardNumber').textContent = data.card_number;
        document.getElementById('resultCardName').textContent = '充值卡'; // 接口暂无卡名称字段
        
        // 处理卡片状态
        const statusElement = document.getElementById('resultCardStatus');
        if (data.status === 1) {
            statusElement.textContent = '未使用';
            statusElement.className = 'result-value card-status-active';
            document.getElementById('resultExpiry').textContent = '无';
            // 未使用的卡密显示"未使用"
            document.getElementById('resultUsageDate').textContent = '未使用';
            document.getElementById('resultUsageDateItem').classList.remove('hidden-item');
            // 未使用的卡密不显示金额
            document.getElementById('resultCardValue').textContent = '***';
        } else if (data.status === 2) {
            statusElement.textContent = '已使用';
            statusElement.className = 'result-value card-status-used';
            // 显示使用时间，如果use_time为0则显示"-"
            document.getElementById('resultUsageDate').textContent = data.use_time && data.use_time !== 0 ? formatDate(data.use_time) : '-';
            document.getElementById('resultExpiryItem').classList.add('hidden-item');
            // 已使用的卡密显示金额
            document.getElementById('resultCardValue').textContent = data.card_value || data.amount || '面值信息';
        } else {
            statusElement.textContent = '未知状态';
            statusElement.className = 'result-value';
            document.getElementById('resultCardValue').textContent = '***';
        }

        // 显示结果区域
        document.getElementById('queryResult').style.display = 'block';
    }

    // 显示错误信息
    function showError2(message) {
        alert(`错误：`+message);
        // 可选：在结果区域显示错误
        // document.getElementById('queryResult').style.display = 'block';
        // document.getElementById('resultCardStatus').textContent = message;
        // document.getElementById('resultCardStatus').className = 'result-value card-status-used';
    }

    // 日期格式化（根据后端返回的日期格式调整）
    function formatDate(timestamp) {
        if (!timestamp || timestamp === 0) return '-';
        // 将时间戳转换为可读的日期格式
        const date = new Date(timestamp * 1000); // 假设是秒级时间戳
        return date.toLocaleString('zh-CN', {
            year: 'numeric',
            month: '2-digit',
            day: '2-digit',
            hour: '2-digit',
            minute: '2-digit',
            second: '2-digit'
        });
    }
</script>
</body>
</html>